<!-- TODO -->
<template>
    <div>
        <!-- header -->
        <el-card class="!border-none" shadow="never">
            <el-form ref="formRef" class="mb-[-16px] mt-[15px]" :inline="true" :model="queryParams">
                <el-form-item label="用户ID搜索">
                    <el-input
                        class="w-[160px] h-[32px]"
                        placeholder="请输入用户ID"
                        v-model="queryParams.uuid"
                        clearable
                    />
                </el-form-item>
				<el-form-item label="用户搜索">
				    <el-input
				        class="w-[160px] h-[32px]"
				        placeholder="请输入手机号/昵称"
				        v-model="queryParams.user_keys"
				        clearable
				    />
				</el-form-item>
                <el-form-item label="中奖类型">
                    <el-select v-model="queryParams.type"   placeholder="全部">
                        <template v-for="(item, index) in goodList">
                            <el-option :label="item.name" :value="item.id" />
                        </template>
                    </el-select>
                </el-form-item>
               <el-form-item label="中奖状态">
                    <el-select
                        placeholder="全部"
                        class="w-[160px] h-[32px]"
                        v-model="queryParams.is_prize_status"
                    >
                        <el-option label="未中奖" :value="1" />
                        <el-option label="已中奖" :value="2" />
                    </el-select>
                </el-form-item>
                <el-form-item label="奖励是否已发放">
                    <el-select
                            placeholder="全部"
                            class="w-[160px] h-[32px]"
                            v-model="queryParams.already_rewarded"
                    >
                        <el-option label="未发放" :value="1" />
                        <el-option label="已发放" :value="2" />
                    </el-select>
                </el-form-item>
                <el-form-item label="抽奖日期区间">
                    <daterange-picker
                        v-model:startTime="queryParams.create_at_start_time"
                        v-model:endTime="queryParams.create_at_end_time"
                        value-format="YYYY-MM-DD"
                    >
                    </daterange-picker>
                </el-form-item>
                <el-form-item label="奖励发放时间">
                    <daterange-picker
                            value-format="YYYY-MM-DD"
                            v-model:startTime="queryParams.already_rewarded_time_start_time"
                            v-model:endTime="queryParams.already_rewarded_time_end_time"
                    >
                    </daterange-picker>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPageNew">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none mt-4" shadow="never">
            <el-table size="large" class="mt-[14px]" :data="pager.lists">
                <el-table-column label="用户ID / 手机号 / 昵称" min-width="120">
                    <template #default="{ row }">
                        {{ row.uuid }} / {{ row.phone }} / {{ row.nickname }}
					</template>
                </el-table-column>
                <el-table-column label="奖品">
                    <template #default="{ row }">
                        <span>{{ row.name }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="中奖状态">
                    <template #default="{ row }">
                        <span>{{ row.is_prize_status == 1 ? '未中奖' : '已中奖'}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="中奖类型">
                    <template #default="{ row }">
                        <span>{{ goodList.find(res => res.id == row.type)?.name }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="奖励是否发放">
                    <template #default="{ row }">
                        <span>{{ row.is_prize_status == 1 ? '未发放' : '已发放'}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="抽奖日期">
                    <template #default="{ row }">
                        <span>{{ row.create_at }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="奖励发放时间">
                    <template #default="{ row }">
                        <span>{{ row.already_rewarded_time }}</span>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 分页 -->
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
    </div>
</template>

<script lang="ts" setup>
import { usePaging } from '@/hooks/usePaging'
import {couponList, getUserTurntablePrizePageList} from '@/api/turntable'
import { getRoutePath } from '@/router'
import feedback from '@/utils/feedback'
import {useDictOptions} from "@/hooks/useDictOptions";

const queryParams = reactive({
    is_prize_status: '', // 中奖状态【1：未中奖|2：已中奖】 不传或空为全部
    type: '', // 类型【1：积分|2：鸡蛋|3：现金红包|4：优惠券|5：商品|6：谢谢惠顾】不传或空为全部
    create_at: '', // 抽奖日期区间 示例值：2024-08-20 - 2024-09-20
    create_at_start_time: '',
    create_at_end_time: '',
    uuid: '',
    already_rewarded:'', // 中奖状态【1：未中奖|2：已中奖】不传或空为全部
    already_rewarded_time:'', // 奖励发放时间 示例值：2024-08-20 - 2024-09-20
    already_rewarded_time_start_time:'',
    already_rewarded_time_end_time:'',
    user_keys:'' //用户搜索【手机号|昵称】
})


const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: getUserTurntablePrizePageList,
    params: queryParams
})
getLists()

const resetPageNew = () => {
    queryParams.create_at = queryParams.create_at_start_time ? `${queryParams.create_at_start_time} - ${queryParams.create_at_end_time}`: ''
    queryParams.already_rewarded_time = queryParams.already_rewarded_time_start_time ? `${queryParams.already_rewarded_time_start_time} - ${queryParams.already_rewarded_time_end_time}`: ''
    getLists()
}

const goodList = [
    {
        id: 1,
        name: '积分'
    },
    {
        id: 2,
        name: '鸡蛋'
    },
    {
        id: 3,
        name: '现金红包'
    },
    {
        id: 4,
        name: '优惠券'
    },
    // {
    //     id: 5,
    //     name: '商品'
    // },
    {
        id: 6,
        name: '谢谢惠顾'
    },
];

const handledel = async (id: number) => {
    // try {
    //     await feedback.confirm('确定要删除？')
    //     await Delteamhead({ id })
    //     feedback.msgSuccess('操作成功')
    //     getLists()
    // } catch (error) {
    //     console.log(error)
    // }
}
</script>
<style lang="scss" scope>
//TODO
.el-alert--warning.is-light {
    background-color: rgba(246, 248, 255, 1);
    color: rgba(64, 115, 250, 1);
}
.text-red {
    color: red;
}
</style>
